<?php

namespace App\Admin\Controllers;

use App\Models\Position;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class PositionController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '招募职位管理';

    private function __($key)
    {
        return [
            'Id' => 'ID',
            'Name' => '招募职位',
            'Created at' => '创建时间',
            'Updated at' => '修改时间',
        ][$key] ?? $key;
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Position());

        $grid->disableFilter();
        $grid->disableExport();
        $grid->disableColumnSelector();
        $grid->disableRowSelector();

        $grid->column('id', $this->__('Id'));
        $grid->column('name', $this->__('Name'));
        $grid->column('created_at', $this->__('Created at'))->display(function($created) {
            return date('Y-m-d H:i:s', strtotime($created));
        });
        $grid->column('updated_at', $this->__('Updated at'))->display(function($created) {
            return date('Y-m-d H:i:s', strtotime($created));
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Position::findOrFail($id));

        $show->field('id', $this->__('Id'));
        $show->field('name', $this->__('Name'));
        $show->field('created_at', $this->__('Created at'));
        $show->field('updated_at', $this->__('Updated at'));
        // $show->field('data', $this->__('Data'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Position());

        $form->text('name', $this->__('Name'));
        // $form->text('data', $this->__('Data'));

        return $form;
    }
}
